package com.h.ssRoom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.h.ssRoom.model.Customers;
import com.h.ssRoom.repo.CustomersRepo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

<<<<<<< HEAD
@CrossOrigin
=======
>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3
@RestController
@RequestMapping(path = "/api",produces = "application/json; charset=utf-8")
public class CustomersContoller {
    @Autowired
    private CustomersRepo customersRepo;

//    @PostMapping(value = "/create_customers")
//    public Map<String,Object> createCustomers(@RequestParam(value = "customerID") String customerID,
//                                           @RequestParam(value = "customerName") String customerName,
//                                           @RequestParam(value = "memLength") Integer memLength,
//                                           @RequestParam(value = "resStatus") Integer resStatus){
//        Map<String,Object> result = new HashMap<>();
//        Customers customers = new Customers();
//        customers.setCustomerID(customerID);
//        customers.setCustomerName(customerName);
//        customers.setMemLength(memLength);
//        customers.setResStatus(resStatus);
//        result.put("status","创建成功");
//        result.put("adminId",customers.getCustomerID());
//        result.put("adminPwd",customers.getCustomerName());
//        customersRepo.save(customers);
//        return result;
//    }

<<<<<<< HEAD
    @GetMapping("/all_customers")
    public List<Customers> findAllCustomers(){
        return customersRepo.findAllCustomers();
    }

    //获取用户信息接口
    @CrossOrigin
    @GetMapping(value = "/customers")
=======
    //获取用户信息接口
    @PostMapping(value = "/customers")
>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3
    public List<Customers> getCustomers(@RequestParam(value ="customerID") String customerID){
        List<Customers> result = customersRepo.getCustomersByCustomerID(customerID);
        return  result;
    }
    
    //修改用户会员时长，订座状态
    @CrossOrigin//解决跨域问题
    @PostMapping(value = "/change_customers")
    public Map<String,Object> changeCustomer(@RequestParam(value = "customerID") String customerID,
                                          @RequestParam(value = "memLength") Integer memLength,
<<<<<<< HEAD
                                          @RequestParam(value = "resStatus") Integer resStatus,
                                          @RequestParam(value = "customerName") String customerName) {
        Map<String, Object> result = new HashMap<>();
        List<Customers> customersList = customersRepo.getCustomersByCustomerID(customerID);
        if (customersList.size() == 0) {
            result.put("failed", "customerID is not exists");
            return result;
        } else {
            customersRepo.updateCustomers(customerID,memLength,resStatus,customerName);
=======
                                          @RequestParam(value = "resStatus") Integer resStatus) {
        Map<String, Object> result = new HashMap<>();
        List<Customers> customersList = customersRepo.getCustomersByCustomerID(customerID);
        if (customersList.size() == 0) {
            result.put("faild", "customerID is not exists");
            return result;
        } else {
            customersRepo.updateCustomers(customerID,memLength,resStatus);
>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3
            result.put("status", "修改用户会员时长，订座状态成功");
            return result;
        }
    }
    
    //删除用户信息接口
    @PostMapping(value ="/delete_customers")
    public Map<String,Object> deleteCustomer(@RequestParam(value ="customerID") String customerID) {
        Map<String, Object> result = new HashMap<>();
        List<Customers> customersList = customersRepo.getCustomersByCustomerID(customerID);
        if(customersList.size() == 0) {
            result.put("faild", "customerID is not exists");
            return result;
        } else {
            customersRepo.deleteCustomers(customerID);
            result.put("status", "删除成功");
            return result;
        }
    }
<<<<<<< HEAD

=======
    //获取用户学习总时长
    @PostMapping(value ="/get_sum_stu_length")
    public Integer getSumStudy(@RequestParam(value ="customerID") String customerID) {
        return customersRepo.getSumStudyLength(customerID);
    }
    
  //获取用户每次学习时长和学习时间
    @PostMapping(value ="/get_per_study")
    public List<Map<String,Object>> getPerStudy(@RequestParam(value ="customerID") String customerID) {
        return customersRepo.getPerStudyRecord(customerID);
    }
>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3

    }

